require([ 'jquery', 'global', 'module/util', 'module/datatables',
		'bootbox.min', 'module/ajax', 'jquery.validate', 'bootstrap',
		'pixeladmin', 'requirejs/domready!' ], function($, global, util,
		datatables, bootbox) {
	window.PixelAdmin.start();

	var bindEvent = function() {

		$("#sav-btn").on("click", function() {
			if ($("#subject").val() == -1) {
				alert("请选择学科！");
				return false;
			}
			if ($("#grade").val() == -1) {
				alert("请选择年级！");
				return false;
			}
			if ($("#term").val() == -1) {
				alert("请选择学期！");
				return false;
			}
			if ($("#edition").val() == -1) {
				alert("请选择版本！");
				return false;
			}

			$(this).submit();
		});
	}

	$('#searchArea').on("change", function() {
		$('#searchArea').attr("autocomplete", "on");
	}).autocomplete(
			{
				source : function(request, response) {
					$.ajax({
						url : global.context + '/web/qcQuestion/getAreaList',
						type : "POST",
						dataType : "json",
						data : {
							'area' : $('#searchArea').val()
						},
						success : function(result) {
							var data = result.data;
							var matcher = new RegExp($.ui.autocomplete
									.escapeRegex(request.term), "i");
							response($.grep(data, function(value) {
								return matcher.test(value.fullName);
							}));
						}
					});
				},
				select : function(event, ui) {
					$("#areaId").val(ui.item.id);
					$("#searchArea").val(ui.item.fullName);
					return false;
				}
			}).data("ui-autocomplete")._renderItem = function(ul, item) {
		return $("<li></li>").data("item.autocomplete", item).append(
				"<a>" + item.fullName + "</a>").appendTo(ul);
	};

	var init = function() {

		bindEvent();

	};

	$("#publishTime").datepicker({
		format : 'yyyy-mm-dd',
		weekStart : 1,
		viewMode : 1,
		autoclose : true,
		todayBtn : 'linked',
		language : 'zh-CN'
	});

	init();
});